#ifndef _LIBFM1208_FM1208_H_
#  define _LIBFM1208_FM1208_H_

#  include <nfc/nfc-types.h>

#define MAX_FRAME_LEN   245
#define MAX_DATA_LEN    239
#define CMD_BASE_LENTH  4   // CLA + INS + P1 + P2

#define CMD_BASE    1       // CLA + INS + P1 + P2
#define CMD_LC      (CMD_BASE   *2)
#define CMD_DATA    (CMD_LC     *2)
#define CMD_LE      (CMD_DATA   *2)
#define CMD_00      (CMD_LE     *2)

#define CMD1    (CMD_BASE | CMD_00)
#define CMD2    (CMD_BASE | CMD_LE)
#define CMD3    (CMD_BASE | CMD_LC | CMD_DATA)
#define CMD4    (CMD_BASE | CMD_LC | CMD_DATA | CMD_LE)

#define SW1SW2_SUCCESS      0x9000
#define SW1SW2_NOTCOMPATY   0x6981
#define SW1SW2_NOSUCHFILE   0x6A82
#define SW1SW2_NORECORD     0x6A83


#define TLV_FCI         0x6F    //文件控制信息
#define TLV_DF          0x84    //df
#define TLV_FCIST       0xA5    //文件控制信息专用模板
#define TLV_DIR         0x88    //DIR短文件标识符
#define TLV_BA          0x4F    //银行应用目录ADF

typedef struct
{
    uint8_t         cla;
    uint8_t         ins;
    uint8_t         p1;
    uint8_t         p2;
    uint8_t         lc;
    const uint8_t   *data;
    uint8_t         le;
} CMD;

typedef struct 
{
    uint8_t     data[MAX_DATA_LEN];
    size_t      size;
    uint16_t    sw1sw2;
} CMD_Response;

typedef struct
{
    uint8_t         tag;
    uint8_t         length;
    uint8_t         value[MAX_DATA_LEN];
} TLV;

void setDebug(bool v);
bool SELECT(nfc_device *pnd, bool fid,const uint8_t *data, size_t dataSize, CMD_Response *res);
bool READ_BINARY(nfc_device *pnd, uint8_t fid,uint16_t offset,CMD_Response *res, size_t resSize);
bool READ_RECORD(nfc_device *pnd, bool encrypt, uint8_t fid,uint8_t recNo,CMD_Response *res, size_t resSize);
bool GET_BALANCE(nfc_device *pnd, bool wallet,uint32_t *balance,CMD_Response *res);


#endif // _LIBFM1208_FM1208_H_
